package com.huaxin.hxcloud.activity;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.huaxin.common.Entity.InfoOrTypeListDTO;
import com.huaxin.common.utils.StringUtils;
import com.huaxin.hxcloud.R;

import java.util.Date;
import java.util.List;


/**
 * @author songxf
 * @date 2017/10/13
 * @Desc 首页新闻adapter
 * Copyright HUAXIN DATA. All rights reserved.
 */
public class HxNewsListAdapter extends BaseMultiItemQuickAdapter<InfoOrTypeListDTO.InfosBean, BaseViewHolder> {

    private Context mContext;

    public HxNewsListAdapter(Context context, List<InfoOrTypeListDTO.InfosBean> data) {
        super(data);
        this.mContext = context;
        //item_info  item_info_type
        addItemType(InfoOrTypeListDTO.InfosBean.TEXT, R.layout.item_info_text);
        addItemType(InfoOrTypeListDTO.InfosBean.IMG, R.layout.item_info_img);
        addItemType(InfoOrTypeListDTO.InfosBean.IMG_TEXT, R.layout.item_info_img_text);
    }

    @Override
    protected void convert(BaseViewHolder helper, InfoOrTypeListDTO.InfosBean item) {
        switch (item.getItemType()) {
            case InfoOrTypeListDTO.InfosBean.TEXT:
                helper.setText(R.id.title_tv, item.getTitle());
                helper.setText(R.id.time_tv, StringUtils.friendlyTime(new Date(item.getCreateDate())));
                ImageView iv_img=helper.getView(R.id.iv_img);
                Glide.with(mContext).load(item.getImg()).apply(new RequestOptions().placeholder(R.drawable.icon_default1)).into(iv_img);
                break;
            case InfoOrTypeListDTO.InfosBean.IMG:
                helper.setText(R.id.title_tv, item.getTitle());
                helper.setText(R.id.time_tv, StringUtils.friendlyTime(new Date(item.getCreateDate())));
                ImageView mNewImg = helper.getView(R.id.new_img);
                Glide.with(mContext).load(item.getImg())
                        .apply(new RequestOptions().placeholder(R.drawable.icon_default1))
                        .into(mNewImg);
                break;
            case InfoOrTypeListDTO.InfosBean.IMG_TEXT:
                helper.setText(R.id.title_tv, item.getTitle());
                helper.setText(R.id.time_tv, StringUtils.friendlyTime(new Date(item.getCreateDate())));
                ImageView mNewImg1 = helper.getView(R.id.new_img);
                Glide.with(mContext).load(item.getImg())
                        .apply(new RequestOptions().placeholder(R.drawable.icon_default1))
                        .into(mNewImg1);
                break;
        }
    }

}

